<div class="fly-panel fly-column">
    <div class="layui-container">
        <ul class="layui-clear">
            <li class="layui-hide-xs {$cateid == 'all' ? 'layui-this' : ''}"><a
                    href="{:url('home/index/index',['cateid' => 'all','state'=>$state])}">首页</a></li>
            {foreach($CateList as $item)}
            <li class="{$cateid == $item.id ? 'layui-this' : ''}"><a
                    href="{:url('home/index/index',['cateid' => $item.id,'state'=>$state])}">{$item.name}</a></li>
            {/foreach}
            <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><span class="fly-mid"></span></li>

            <!-- 用户登入后显示 -->
            {if($LoginUser)}
            <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="{:url('home/user/post')}">我发表的贴</a></li>
            <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a
                    href="{:url('home/collection/index')}">我收藏的贴</a></li>
            {/if}
        </ul>

        <div class="fly-column-right layui-hide-xs">
            <span class="fly-search"><i class="layui-icon"></i></span>
            <a href="{:url('home/post/add')}" class="layui-btn">发表新帖</a>
        </div>
        <div class="layui-hide-sm layui-show-xs-block"
            style="margin-top: -10px; padding-bottom: 10px; text-align: center;">
            <a href="{:url('home/post/add')}" class="layui-btn">发表新帖</a>
        </div>
    </div>
</div>
<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8">
            

            <div class="fly-panel" style="margin-bottom: 0;">

                <!-- 筛选 -->
                <div class="fly-panel-title fly-filter">
                    <a href="{:url('home/index/index', ['cateid'=>$cateid, 'state'=>'all'])}"
                        class="{$state == 'all' ? 'layui-this': ''}">全部</a>
                    <span class="fly-mid"></span>
                    <a href="{:url('home/index/index', ['cateid'=>$cateid,'state'=>1])}"
                        class="{$state == '1' ? 'layui-this': ''}">置顶</a>
                    <span class="fly-mid"></span>
                    <a href="{:url('home/index/index', ['cateid'=>$cateid,'state'=>2])}"
                        class="{$state == '2' ? 'layui-this': ''}">精华</a>
                    <span class="fly-mid"></span>
                    <a href="{:url('home/index/index', ['cateid'=>$cateid,'state'=>3])}"
                        class="{$state == '3' ? 'layui-this': ''}">热门</a>
                    <span class="fly-mid"></span>
                    <a href="{:url('home/index/index', ['cateid'=>$cateid,'state'=>0])}"
                        class="{$state == '0' ? 'layui-this': ''}">常规</a>
                    <span class="fly-filter-right layui-hide-xs">
                        <a href="{:url('home/index/index', ['cateid'=>$cateid,'state'=>$state,'accept'=>''])}"
                            class="{$accept == '' ? 'layui-this' : ''}">未采纳</a>
                        <span class="fly-mid"></span>
                        <a href="{:url('home/index/index', ['cateid'=>$cateid,'state'=>$state,'accept'=>1])}"
                            class="{$accept == 1 ? 'layui-this' : ''}">已采纳</a>
                    </span>
                </div>

                {if(count($PostList) > 0)}
                <ul class="fly-list">
                    {foreach $PostList as $key => $item}
                    <li>
                        <a href="{:url('home/user/index',['userid' => $item.userid])}" class="fly-avatar">
                            <img src="{$item.user.avatar ? $item.user.avatar : '/static/home/res/images/avatar/default.png'}"
                                alt="{$item.user.nickname}">
                        </a>
                        <h2>
                            <a class="layui-badge">{$item.cate.name}</a>
                            <a href="{:url('home/index/info',['postid' => $item.id])}">{$item.title}</a>
                        </h2>
                        <div class="fly-list-info">
                            <a href="{:url('home/user/index',['userid' => $item.userid])}" link>
                                <cite>{$item.user.nickname}</cite>
                                {if($item.user.auth == 1)}
                                <i class="iconfont icon-renzheng" title="认证信息：{$item.user.nickname}"></i>
                                {/if}

                                {if($item.user.vip)}
                                <i class="layui-badge fly-badge-vip">VIP {$item.user.vip}</i>
                                {/if}

                            </a>
                            <span>{$item.createtime|date="Y-m-d H:i"}</span>

                            <span class="fly-list-kiss layui-hide-xs" title="悬赏飞吻">
                                <i class="iconfont icon-kiss"></i>
                                {$item.point}
                            </span>
                            {if($item.accept)}
                            <span class="layui-badge fly-badge-accept layui-hide-xs">已结</span>
                            {/if}
                            <span class="fly-list-nums">
                                <i class="iconfont icon-pinglun1" title="回答"></i>
                                {$item.comment_total}
                            </span>
                        </div>
                        <div class="fly-list-badge">
                            {if($item.state eq 1)}
                            <span class="layui-badge layui-bg-black">置顶</span>
                            {elseif($item.state eq 2) /}
                            <span class="layui-badge layui-bg-red">精华</span>
                            {elseif($item.state eq 3) /}
                            <span class="layui-badge layui-bg-orange">热门</span>
                            {/if}
                        </div>
                    </li>
                    {/foreach}

                </ul>
                {else /}
                    <div class="fly-none" style="min-height: 70px;">暂无帖子</div>
                {/if}

                {$PostList|raw}
            </div>
        </div>
        <div class="layui-col-md4">

            <div class="fly-panel fly-signin">
                <div class="fly-panel-title">
                    签到
                </div>
                <div class="fly-panel-main fly-signin-main">
                    {if($LoginUser)}
                    {if(isset($LoginUser['sign']) && $LoginUser['sign'])}
                    <!-- 已签到状态 -->
                    <button class="layui-btn layui-btn-disabled">
                        今日已签到
                    </button>
                    <span>获得了<cite>{$SignPoint}</cite>积分</span>
                    {else /}
                    <button id="sign" class="layui-btn layui-btn-danger">
                        今日签到
                    </button>
                    <span>可获得<cite>{$SignPoint}</cite>积分</span>
                    {/if}
                    {else /}
                    <button id="sign" class="layui-btn layui-btn-danger">
                        今日签到
                    </button>
                    <span>可获得<cite>{$SignPoint}</cite>积分</span>
                    {/if}
                </div>
            </div>

            <div class="fly-panel">
                <h3 class="fly-panel-title">本周热议</h3>
                <ul class="fly-panel-main fly-list-static">
                    {if($PostWeek)}
                        {foreach($PostWeek as $item)}
                            <li>
                                <a href="{:url('home/index/info',['postid' => $item.post.id])}" target="_blank">{$item.post.title}</a>
                            </li>
                        {/foreach}
                    {else /}
                        <div class="fly-none">暂无热议</div>
                    {/if}

                    
                </ul>
            </div>

            <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
                <h3 class="fly-panel-title">回贴周榜</h3>
                <dl>
                    <!--<i class="layui-icon fly-loading">&#xe63d;</i>-->
                    {if($CommentWeek)}
                        {foreach($CommentWeek as $item)}
                            <dd>
                                <a href="{:url('home/user/index',['userid' => $item.user.id])}">
                                    <img src="{$item.user.avatar ? $item.user.avatar : '/static/home/res/images/avatar/default.png'}">
                                    <cite>{$item.user.nickname}</cite>
                                    <i>{$item.num}次回答</i>
                                </a>
                            </dd>
                        {/foreach}
                    {else /}
                        <div class="fly-none">暂无回贴</div>
                    {/if}
                    
                </dl>
            </div>

            <div class="fly-panel" style="padding: 20px 0; text-align: center;">
                <img src="/static/home/res/images/weixin.jpg" style="max-width: 100%;" alt="layui">
                <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['jquery'], function () {
        var $ = layui.jquery

        //给签到按钮绑定点击事件
        $('#sign').click(function () {

            $.ajax({
                url: `{:url('home/index/sign')}`,
                type: 'post',
                dataType: 'json',
                success: function (result) {
                    console.log(result)
                    if (result.code) {
                        //成功
                        layer.msg(result.msg,{ icon: 1, time: 1000 },function () {
                            $("#sign").addClass('layui-btn-disabled')
                            $("#sign").text('今日已签到')
                        })
                    } else {
                        //失败
                        layer.msg(result.msg)
                    }
                }
            })
        })
    })
</script>